//
//  SkillTableViewCell.m
//  BasketballClub
//
//  Created by 孙鸿吉 on 16/1/6.
//  Copyright © 2016年 孙鸿吉. All rights reserved.
//

#import "SkillTableViewCell.h"
#import "SkillModel.h"
#import <UIImageView+WebCache.h>
#import <AVOSCloud.h>
@interface SkillTableViewCell()
@property (nonatomic,assign)NSInteger readCount;
- (NSString *)transTime:(NSString *)date;

@end
@implementation SkillTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    }
    return self;
}
- (void)addFirstStyleCell
{
    //标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 10 * LAYOUT_SIZE_HEIGHT, SCREEN_WIDTH - (20 * LAYOUT_SIZE), 30 * LAYOUT_SIZE_HEIGHT)];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(17 * LAYOUT_SIZE)];
    [self.contentView addSubview:self.titleLabel];
    //时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 70 * LAYOUT_SIZE_HEIGHT, 55 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.timeLabel.textColor = [UIColor lightGrayColor];
    self.timeLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.timeLabel];
    //阅读人数
    self.peoplesLabel = [[UILabel alloc]initWithFrame:CGRectMake(60 * LAYOUT_SIZE, 70 * LAYOUT_SIZE_HEIGHT, 30 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.peoplesLabel.textColor = [UIColor lightGrayColor];
    self.peoplesLabel.textAlignment = 2;
    self.peoplesLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.peoplesLabel];
    //人阅读
    self.readLabel = [[UILabel alloc]initWithFrame:CGRectMake(90 * LAYOUT_SIZE, 70 * LAYOUT_SIZE_HEIGHT, 40 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.readLabel.textColor = [UIColor lightGrayColor];
    self.readLabel.text = @"人阅读";
    self.readLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.readLabel];
}
- (void)addSecondSytleCell
{
    //标题
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 10 * LAYOUT_SIZE_HEIGHT, 230 * LAYOUT_SIZE, 30 * LAYOUT_SIZE_HEIGHT)];
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(17 * LAYOUT_SIZE)];
    [self.contentView addSubview:self.titleLabel];
    //图片
    self.skillImageVeiw1 = [[UIImageView alloc]initWithFrame:CGRectMake(245 * LAYOUT_SIZE, 10 * LAYOUT_SIZE_HEIGHT, SCREEN_WIDTH - (255 * LAYOUT_SIZE), 110 * LAYOUT_SIZE_HEIGHT)];
    [self.contentView addSubview:self.skillImageVeiw1];
    //时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 100 * LAYOUT_SIZE_HEIGHT, 50 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.timeLabel.textColor = [UIColor lightGrayColor];
    self.timeLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.timeLabel];
    //阅读人数
    self.peoplesLabel = [[UILabel alloc]initWithFrame:CGRectMake(55 * LAYOUT_SIZE, 100 * LAYOUT_SIZE_HEIGHT, 30 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.peoplesLabel.textColor = [UIColor lightGrayColor];
    self.peoplesLabel.textAlignment = 2;
    self.peoplesLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.peoplesLabel];
    //人阅读
    self.readLabel = [[UILabel alloc]initWithFrame:CGRectMake(85 * LAYOUT_SIZE, 100 * LAYOUT_SIZE_HEIGHT, 40 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.readLabel.textColor = [UIColor lightGrayColor];
    self.readLabel.text = @"人阅读";
    self.readLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.readLabel];

}
- (void)addThirdStyleCell
{
    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 10 * LAYOUT_SIZE_HEIGHT, SCREEN_WIDTH - (20 * LAYOUT_SIZE), 30 * LAYOUT_SIZE_HEIGHT)];
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:(17 * LAYOUT_SIZE)];
    [self.contentView addSubview:self.titleLabel];
    //图片
    self.skillImageVeiw1 = [[UIImageView alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 50 * LAYOUT_SIZE_HEIGHT, (SCREEN_WIDTH - (20 * LAYOUT_SIZE))/3, 100 * LAYOUT_SIZE_HEIGHT)];
    [self.contentView addSubview:self.skillImageVeiw1];
    self.skillImageView2 = [[UIImageView alloc]initWithFrame:CGRectMake((10 * LAYOUT_SIZE)+(LAYOUT_SIZE, (SCREEN_WIDTH - (20 * LAYOUT_SIZE_HEIGHT))/3), 50 * LAYOUT_SIZE, (SCREEN_WIDTH - (20 * LAYOUT_SIZE))/3, 100 * LAYOUT_SIZE_HEIGHT)];
    [self.contentView addSubview:self.skillImageView2];
    self.skillImageView3 = [[UIImageView alloc]initWithFrame:CGRectMake((10 * LAYOUT_SIZE)+(LAYOUT_SIZE, (SCREEN_WIDTH - (20 * LAYOUT_SIZE_HEIGHT))/3)*2, 50 * LAYOUT_SIZE, (SCREEN_WIDTH - (20 * LAYOUT_SIZE))/3, 100 * LAYOUT_SIZE_HEIGHT)];
    [self.contentView addSubview:self.skillImageView3];
    //时间
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10 * LAYOUT_SIZE, 160 * LAYOUT_SIZE_HEIGHT, 45 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.timeLabel.textColor = [UIColor lightGrayColor];
    self.timeLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.timeLabel];
    //阅读人数
    self.peoplesLabel = [[UILabel alloc]initWithFrame:CGRectMake(50 * LAYOUT_SIZE, 160 * LAYOUT_SIZE_HEIGHT, 30 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.peoplesLabel.textColor = [UIColor lightGrayColor];
    self.peoplesLabel.textAlignment = 2;
    self.peoplesLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.peoplesLabel];
    //人阅读
    self.readLabel = [[UILabel alloc]initWithFrame:CGRectMake(80 * LAYOUT_SIZE, 160 * LAYOUT_SIZE_HEIGHT, 40 * LAYOUT_SIZE, 20 * LAYOUT_SIZE_HEIGHT)];
    self.readLabel.textColor = [UIColor lightGrayColor];
    self.readLabel.text = @"人阅读";
    self.readLabel.font = [UIFont systemFontOfSize:12 * LAYOUT_SIZE];
    [self.contentView addSubview:self.readLabel];
}

#pragma mark - cell赋值方法
- (void)getDataFromSkillModel:(SkillModel *)model
{
    //标题
    self.titleLabel.text = model.title;
    self.timeLabel.text = [self transTime:model.time];
    self.peoplesLabel.text = [NSString stringWithFormat:@"%@",model.readarts];
}
- (void)getDataTwoFromSkillModel:(SkillModel *)model
{
    self.titleLabel.text = model.title;
    self.timeLabel.text = [self transTime:model.time];
    self.peoplesLabel.text = [NSString stringWithFormat:@"%@",model.readarts];
    [self.skillImageVeiw1 sd_setImageWithURL:[NSURL URLWithString:model.imageArray[0]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
}
- (void)getDataThreeFromSkillModel:(SkillModel *)model
{
    self.titleLabel.text = model.title;
    self.timeLabel.text = [self transTime:model.time];
    self.peoplesLabel.text = [NSString stringWithFormat:@"%@",model.readarts];
    [self.skillImageVeiw1 sd_setImageWithURL:[NSURL URLWithString:model.imageArray[1]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    [self.skillImageView2 sd_setImageWithURL:[NSURL URLWithString:model.imageArray[2]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
    [self.skillImageView3 sd_setImageWithURL:[NSURL URLWithString:model.imageArray[3]] placeholderImage:[UIImage imageNamed:@"zhanwei"]];
}
#pragma mark - 换算时间方法
- (NSString *)transTime:(NSString *)date
{
    NSDate *dateNow = [NSDate date];
    NSInteger duration = (NSInteger)[dateNow timeIntervalSince1970] - [date integerValue];
    NSString *string = [NSString new];
    int second = 1;
    int minute = second * 60;
    int hour = minute * 60;
    int day = hour * 24;
    int week = day * 7;
    int month = day * 31;
    if (duration <= 7 * second) {
        string = @"刚刚发布";
    }else if (duration < minute) {
        int n = (int)duration/second;
        string = [NSString stringWithFormat:@"%d秒钟前",n];
    }else if (duration < hour){
        int n = (int)duration/minute;
        string = [NSString stringWithFormat:@"%d分钟前",n];
    }else if (duration < day){
        int n = (int)duration/hour;
        string = [NSString stringWithFormat:@"%d小时前",n];
    }else if (duration < week){
        int n = (int)duration/day;
        string = [NSString stringWithFormat:@"%d天以前",n];
    }else if (duration < month){
        int n = (int)duration/week;
        string = [NSString stringWithFormat:@"%d周以前",n];
    }else if (duration > month){
        string = @"很久以前";
    }
    return string;
}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
